﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharpStudy
{
    //反面例子，没有使用依赖注入
    class DI_NoDesign
    {
        //public static void Main(string[] args)
        //{
        //    Role_DI Jay=new Role_DI(){Name = "周杰伦"};
        //    Jay.Weapon = new Weapon_DI("倚天剑");
        //    Monster_DI Duck=new Monster_DI("半兽人"){HP = 60};
        //    Jay.Hit(Duck);
        //    Jay.Weapon = new Weapon_DI("木剑");
        //    Jay.Hit(Duck);
        //    Console.ReadLine();
        //}
    }

    /// <summary>
    /// 怪兽类
    /// </summary>
    class Monster_DI
    {
        /// <summary>
        /// 怪兽名字
        /// </summary>
        public string Name { get;private set; }

        /// <summary>
        /// 血量
        /// </summary>
        public int HP { get; set; }

        public Monster_DI()
        {
        }

        public Monster_DI(string monsterName)
        {
            Name = monsterName;
        }
    }

    /// <summary>
    /// 角色类
    /// </summary>
    class Role_DI
    {
        /// <summary>
        /// 名字
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 武器
        /// </summary>
        public Weapon_DI Weapon { get; set; }


        /// <summary>
        /// 攻击
        /// </summary>
        /// <param name="monster"></param>
        public void Hit(Monster_DI monster)
        {
            if (string.IsNullOrEmpty(Weapon.Name))
            {
                return;
            }
            if (monster.HP<=0)
            {
                Console.WriteLine("怪物已死！");
                return;
            }
            switch (Weapon.Name)
            {
                case "倚天剑":
                    Console.WriteLine(monster.Name + "当前血量:" + monster.HP);
                    Console.WriteLine(Name+"使用" + Weapon.Name + "攻击:" + monster.Name);
                    Console.WriteLine(monster.Name + "被砍掉50HP");
                    monster.HP -= 50;
                    Console.WriteLine("怪物" + monster.Name + "剩余血量：" + monster.HP);
                    IsDead(monster.HP);
                    break;
                case "木剑":
                    Console.WriteLine(monster.Name + "当前血量:" + monster.HP);
                    Console.WriteLine(Name+"使用" + Weapon.Name + "攻击:" + monster.Name);
                    Console.WriteLine(monster.Name + "被砍掉50HP");
                    monster.HP -= 10;
                    Console.WriteLine("怪物" + monster.Name + "剩余血量：" + monster.HP);
                    IsDead(monster.HP);
                    break;
            }
        }

        static bool IsDead(int hp)
        {
            if (hp <= 0)
            {
                Console.WriteLine("怪物已经被砍死！");
            }
            return hp > 0;
        }
    }

    class Weapon_DI
    {
        /// <summary>
        /// 武器名字
        /// </summary>
        public string Name { get;private set; }

        public Weapon_DI()
        {
        }

        public Weapon_DI(string weaponName)
        {
            Name = weaponName;
        }
        
    }
}
